home *** CD-ROM | disk | FTP | other *** search
/ Light ROM Gold / Light ROM Gold.iso / arexx / multi_p.lwm < prev    next >
Text File  |  1995-09-04  |  5KB  |  191 lines

  1. /* MultiPoints.lwm -- CMD: Multiply Points 
  2.  * Copyright ⌐ 1995 J. Pehrson.  WWW:   http://www.hfb.se/~d93jpe/.html 
  3.  *                               EMail: d93jpe@t.hfb.se, jpehrson@kuai.se
  4.  *                                
  5.  * WHY?
  6.  * I wrote this macro because I needed a easy way to do a "line" of points 
  7.  * for the LightSwarm macro for a project a while ago.  (I had to make an 
  8.  * edge look like melted metal, and added lots of lights with lensflares 
  9.  * (LightSwarm) to the subdivided edge(this macro) Came out pretty good.
  10.  * Maybe overkill, but...) 
  11.  * And I made the macro as a tutorial in ARexx, since this is my first 
  12.  * attempt to do anything in the language.
  13.  *
  14.  * GUI:
  15.  * Number of points to add  = It's the number of points you want to add
  16.  *                            between all (selected) points
  17.  * Use only selected points = If checked, the macro will use only the
  18.  *                            currently selected points.  If unchecked 
  19.  *                            the macro will add points between all points
  20.  *                            in the layer.
  21.  *
  22.  * Connect first/last points = This button controls wheather or not the
  23.  *                             first and the last point is going to 
  24.  *                             have points added between them.
  25.  *
  26.  * BUGS:  
  27.  * ░The order in which you created the points is used, not the order in which
  28.  *  you selected the points. Can give some undesired results. Will be fixed
  29.  *  if I find out how to do it...
  30.  * ░The progress meter isn't updated correctly. (At least not on my system)
  31.  *  Maybe it's a question of CPU speed...
  32.  *
  33.  * DISCLAIMER:
  34.  * Use this macro at YOUR own risc...  It may blow up your computer, or it
  35.  * could destroy the project you've been working on for the last couple 
  36.  * of years.
  37.  * But the macro works for ME!  So, use it at YOUR own risc.  There.  
  38.  * No more talk, lets AREXX!
  39.  *
  40.  * $VER:  MultiPoints.lwm v2.1 August 9 1995 LightWave Macro 
  41.  */
  42.  
  43. newpoints    = 10
  44. selectpoints = 1
  45. closepoints  = 0
  46.  
  47. macroname    = 'Multiply Points v2.1'
  48. prefsname    = 'ENV:MPointsLW.prefs'
  49.  
  50. if (exists(prefsname)) then do
  51.     if (~open(prefs, prefsname, 'R')) then break
  52.     if (readln(prefs) ~= macroname) then break
  53.     parse value readln(prefs) with newpoints selectpoints closepoints from .
  54.     call close prefs
  55. end
  56.  
  57. address = 'LWModelerARexx.port'
  58. L=SHOW('Libraries')
  59. IF POS(address,l) = 0 THEN ADDLIB("LWModelerARexx.port",0)
  60. call addlib("rexxmathlib.library",0,-30,0)
  61. signal on error
  62. signal on syntax
  63.  
  64. call req_begin macroname
  65.  
  66. id_Np = req_addcontrol("Number of points to add",'N',0)
  67. id_Ap = req_addcontrol("Use only selected points?",'B',0)
  68. id_Cp = req_addcontrol("Connect first/last points?",'B',0)
  69. call req_setval id_Np, newpoints
  70. call req_setval id_Ap, selectpoints
  71. call req_setval id_Cp, closepoints
  72.  
  73. if (~req_post()) then do
  74.   call req_end
  75.   exit
  76. end
  77.  
  78. newpoints=req_getval(id_Np)
  79. selectpoints=req_getval(id_Ap)
  80. closepoints=req_getval(id_Cp)
  81. call req_end
  82.  
  83. if (open(prefs, prefsname, 'W')) then do
  84.     call writeln prefs, macroname
  85.     call writeln prefs, newpoints selectpoints closepoints from
  86.     call close prefs
  87. end
  88.  
  89. gtotpoints=xfrm_begin()
  90. call xfrm_end()
  91.  
  92. if(selectpoints~=0) then do
  93.   call sel_mode(USER)
  94. end
  95.  
  96. if(xfrm_begin()<2) then do
  97.   call notify(1,'!You have to create at least 2 points before running this macro!')
  98.   call end_all
  99.   exit
  100. end
  101.  
  102. selpoints = xfrm_begin()
  103. call xfrm_end()
  104.  
  105. totpoints = (selpoints-1)*newpoints+gtotpoints
  106.  
  107. if(closepoints~=0) then do
  108.   totpoints=totpoints+newpoints+gtotpoints
  109. end
  110.  
  111. totpoints=substr(totpoints,1,(lastpos('.',totpoints))-1,' ')
  112. newpoints=substr(newpoints,1,(lastpos('.',newpoints))-1,' ')
  113.  
  114. if totpoints > 65000 then do
  115.   if (closepoints~=0) then do
  116.     call notify(1,'!'newpoints'x'selpoints' gives 'totpoints' points.',' Too many! Cannot count that high.')
  117.     exit
  118.     end
  119.   call notify(1,'!'newpoints'x'selpoints-1' gives 'totpoints' points.',' Too many! Cannot count that high.')
  120.   exit
  121. end
  122.  
  123. if((selpoints<=2)&(closepoints~=0)) then do
  124.   call notify(1,'!Number of sel. points='selpoints'. Will not close first/last points!')
  125.   closepoints=0
  126. end
  127. totpoints=0
  128.  
  129. do i=1 to selpoints-1
  130.   call xfrm_begin()
  131.   vec1=xfrm_getpos(i)
  132.   vec2=xfrm_getpos(i+1)
  133.   call xfrm_end()
  134.   call time 'R'
  135.   call setcomp
  136.   call plotpoints 
  137. end
  138.  
  139. if(closepoints~=0) then do
  140.   call xfrm_begin()
  141.   vec1=xfrm_getpos(1)
  142.   vec2=xfrm_getpos(selpoints)
  143.   call xfrm_end()
  144.   call setcomp
  145.   call plotpoints 
  146. end  
  147.  
  148. ETA=time('E')
  149. call notify(1,'Whew! I just drew 'totpoints' points in 'ETA' seconds!')
  150. call end_all
  151. exit
  152.  
  153. syntax:
  154. error:
  155.   call end_all
  156.     t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  157.     exit
  158. end
  159.  
  160. plotpoints:
  161. call meter_begin(newpoints,"Generating "newpoints" points")
  162. call add_begin()
  163. do k=1 to newpoints
  164.   Xn=X0+Rx0*segment*k
  165.   Yn=Y0+Ry0*segment*k
  166.   Zn=Z0+Rz0*segment*k   
  167.   call add_point(Xn' 'Yn' 'Zn)
  168.   totpoints=totpoints+1
  169.   call meter_step()
  170. end
  171. call add_end()
  172. call meter_end()
  173. return 0
  174.  
  175. setcomp:
  176. X0=word(vec1,1)
  177. Y0=word(vec1,2)
  178. Z0=word(vec1,3)
  179. X1=word(vec2,1)
  180. Y1=word(vec2,2)
  181. Z1=word(vec2,3)
  182. Rx0=X1-X0
  183. Ry0=Y1-Y0
  184. Rz0=Z1-Z0
  185. Z=sqrt((Rx0**2)+(Ry0**2)+(Rz0**2))
  186. Rx0=Rx0/Z
  187. Ry0=Ry0/Z
  188. Rz0=Rz0/Z
  189. segment=Z/(newpoints+1)
  190. return 0
  191.